<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysqli.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
if(isset($_POST['submit'])){
    // var_dump($_POST);exit();
    foreach($_POST['sort'] as $key=>$val){
         if(!is_numeric($val)||!is_numeric($key)){
             skip('childModule.php','error','输入参数不合法！ ');
         }    
         $query[]="update childModule set sort=$val where id=$key";
    } 
         $result=execute_multi($link,$query,$error);
         if($result){
             skip('childModule.php','ok','修改成功！ ');
         }else{
             skip('childModule.php','error',$error);
    }
 }
?>
<?php
$template='子板块列表';
include_once 'inc/header.inc.php';
?>
    <div id="main">
    <div class="intro"><?php echo $template ?></div>
    <form method="post">
        <table class="cont">
            <tr>
                <th>排序</th>
                <th>子板块名称</th>
                <th>所属父板块</th>
                <th>版主</th>
                <th>操作</th>
            </tr>
 <?php
    $query="select *from childModule order by referid";
    $result=execute($link,$query);
    while($data=mysqli_fetch_assoc($result)){
        $data=dehtml($data);
        $url=urlencode("cm_delete.php?id={$data['id']}");
        $rturl=urlencode("$_SERVER[REQUEST_URI]");
        $message=urlencode("确认要删除该子板块 <span style='color:rgb(218, 126, 114);'>{$data['moduleName']}</span> 的内容么？&nbsp;&nbsp;");
        $delurl="confirm.php?url={$url}&rturl={$rturl}&message={$message}";
        $upurl="cm_update.php?id={$data['id']}";

        $queryf="select *from fatherModule where id={$data['referid']}";
        $resultf=execute($link,$queryf);
        $dataf=mysqli_fetch_array($resultf);
        $dataf=dehtml($dataf);
$html=<<< A
    <tr>
        <td><input class="sort" type="text" name="sort[{$data['id']}]" value="{$data['sort']}" /></td>
        <td>{$data['moduleName']}[id:{$data['id']}]</td>
        <td>{$dataf['moduleName']}[id:{$dataf['id']}]</td>
        <td>bgape002</td>
        <td><a href="#">[访问]</a>&nbsp;&nbsp;<a href="$upurl">[编辑]</a>&nbsp;&nbsp;<a href="$delurl">[删除]</a></td>
    </tr>
A;
        echo $html;
    }
 ?>
            
        </table>
        <div class="division"></div>
        <input type="submit" name="submit" value="排序" class="nsubmit" />
    </form>
    </div>

<?php
    include_once 'inc/footer.inc.php';
?>